10. Connecting to the Database
Hello App with Flask-SQLAlchemy Heading
Hello App with Flask-SQLAlchemy
ND004 C01 L03 10 Hello App With Flask-SQLAlchemy
QUIZ QUESTION: :
Here's an example URI:
'postgresql://myusername:mypassword@localhost:5432/mydatabase'
Can you name each part?
ANSWER CHOICES:
Part of URI |
Name |
---|---|
password (optional) |
|
port |
|
database name |
|
dialect |
|
host address |
|
username |
SOLUTION:
Part of URI |
Name |
---|---|
password (optional) |
|
port |
|
database name |
|
dialect |
|
host address |
|
username |
ND004 C01 L03 10.1 Hello App With Flask-SQLAlchemy
Code
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://udacitystudios@localhost:5432/example'
db = SQLAlchemy(app)
Hello App with Flask-SQLAlchemy Recap
Let's practice. Complete Exercise 2.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: jupyter-lab
- Opened files (when workspace is loaded): n/a